
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import vn.hus.nlp.sd.SentenceDetector;
import GlobalVar.Constan;

/**
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author thắng
 */
public class sentenceDetector {//sử dụng bộ phân tách câu

    public void sentDet() {
        Constan constan = new Constan();
        //<W NSW="NONE" FULL="XXX">﻿</W>
        String pre = "<W NSW=\"SENT\" FULL=\"___\">";
        String dot = ".";
        String suf = "</W>";
        try {
            SentenceDetector test = new SentenceDetector(constan.SentenceDetectorModel);//load file model.bin vao mo hinh
            String[] str = test.detectSentences(constan.testSentenceDetector);//dau vao de phan tach cau
            StringBuilder sb = new StringBuilder();
            System.out.println("so cau: "+str.length);
            for (int i = 0; i < str.length; i++) {
                String string = str[i];
                int li = string.length();
                System.out.print("cau thu " + i + ", ");
                System.out.println("do dai cau " + li);
                //System.out.print("cau goc: " + string);
                System.out.print("ky tu cuoi cung la \"" + string.charAt(li - 1) + "\"; ");
                sb.append(i);
                sb.append(": ");
                if (((string.endsWith(".") | string.endsWith(",") | string.endsWith(";") | string.endsWith("!") | string.endsWith("?")) && (!string.endsWith("...")))) {
                    //System.out.println(str[i].charAt(li-1));
                    sb.append(string, 0, li - 1);
                    sb.append(pre);
                    sb.append(string.charAt(li - 1));
                    sb.append(suf);
                } else {
                    sb.append(string);
                    sb.append(pre);
                    sb.append(dot);
                    sb.append(suf);
                }
                sb.append(System.getProperty("line.separator"));
            }
            System.out.println(sb.toString() + "what the f?");
        } catch (IOException ex) {
            Logger.getLogger(Temp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args) {
        sentenceDetector obj = new sentenceDetector();
        obj.sentDet();
    }
}
